﻿using System;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Windows;

namespace Loader
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App
    {
        static App()
        {
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
            Thread.CurrentThread.Priority = ThreadPriority.Highest;
            AssemblyLoader.ResolveAssemblies<Resources>(
                AppDomain.CurrentDomain,
                bytes => Foundation.Compressor.ConvertBytes(bytes));
        }

        private void App_OnStartup(object sender, StartupEventArgs args)
        {
            try
            {
                var configuration = ConfigurationManager.OpenExeConfiguration(Assembly.GetEntryAssembly().Location);
                if (!configuration.HasFile)
                    File.WriteAllText(configuration.FilePath, Loader.Resources.app);
                new Poet.AppLoader(this).Run(sender, args);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
    }
}
